package com.kla.power.controller;

import com.kla.power.config.LogPointer;
import com.kla.power.entity.AreaEntity;
import com.kla.power.service.IAreaService;
import com.kla.power.util.ResultBody;
import com.kla.power.util.SnowflakeIdWorker;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 省市县区 前端控制器
 * </p>
 *
 * @author WuZH
 * @since 2023-06-23
 */
@RestController
@RequestMapping ( "/area" )
@CrossOrigin ( value = "*", maxAge = 3600 )
public class AreaController {

    @Resource
    private IAreaService iAreaService;

    @RequestMapping ( "queryList" )
    @LogPointer ("城市区域列表")
    public ResultBody queryList (@RequestBody AreaEntity areaEntity ) {
        List<AreaEntity> areaEntities = iAreaService.queryList ( areaEntity );
        return ResultBody.success ( areaEntities );
    }

    @RequestMapping ( "saveSingle" )
    @LogPointer("保存城市区域")
    public ResultBody saveSingle ( @RequestBody AreaEntity areaEntity ) {
        areaEntity.setId ( SnowflakeIdWorker.getInstance ().nextStringId () );
        areaEntity = iAreaService.saveSingle ( areaEntity );
        return ResultBody.success ( areaEntity );
    }

}
